## Import gtk
import sys
try:
    import pygtk
    pygtk.require("2.0")
except:
    pass
try:
    import gtk
    import gtk.glade
except:
    print("GTK Not Availible")
    sys.exit(1)

## Import Book
sys.path.append( "../imageFeatures_classes" )
import AiBook
import AiBlob

class AiCompareGui:
    wTree = None

    def __init__( self, book ):
        self.book = book
        if __debug__:
            assert book.blobsTraced

        self.wTree = gtk.glade.XML( "compareBlobs.glade" )
        self.dia = self.wTree.get_widget("dialogCompareBlob")

        dictionary = {
            "on_buttonCompare_clicked" : self.compare,
            "on_buttonCancel_clicked" : self.quit,
            "on_dialogCompareBlob_destroy" : self.quit
        }

        self.wTree.signal_autoconnect( dictionary )
        self.dia.show()

    def compare(self, widget):
        b1ID = (self.wTree.get_widget("spinbuttonBlob1Pagenr").get_value_as_int(),\
                self.wTree.get_widget("spinbuttonBlob1Blobnr").get_value_as_int())
        b2ID = (self.wTree.get_widget("spinbuttonBlob2Pagenr").get_value_as_int(),\
                self.wTree.get_widget("spinbuttonBlob2Blobnr").get_value_as_int())
        b1 = self.book.getBlobById(b1ID)
        b2 = self.book.getBlobById(b2ID)

        p = AiBlob.compareBlobs(b1,b2)
        self.wTree.get_widget("labelP").set_text(str(p))

    def quit(self, widget):
        self.dia.destroy()


